<template>
	<view>
		<u-loading-page :loading="isPageLoading" :loading-text="loadingPageText"></u-loading-page>
		<view v-if="!isPageLoading">
			<view class="qybg_top">
				<view class="title">企业分析报告</view>
				<view class="company">{{company}}</view>
			</view>
			<view class="qybg_price">
				<view>
					<text class="xianjia">¥{{sjprice}}</text>
					<text class="yuanjia" v-show="sjprice !== yuanjia">¥{{yuanjia}}</text>
				</view>
				<view class="cishu" v-show="count > 0 && !isshowEmail">随会员赠送下载次数：<text>{{count}}</text> 次</view>
			</view>
			<view class="qybg_qysf">
				<view class="qysf_title">企业身份</view>
				<view class="qysf_box">
					<view class="qysf_item active  d-b-c" style="padding: 0 15rpx;" @click="shenfenChange">
						{{qiyeshenfen == 2 ?'业主版' : qiyeshenfen == 4 ? '供应商版' : '代理商版'}}
						<u-icon name="arrow-down" size="24rpx" color="#2F6DFE"></u-icon>
					</view>
				</view>
				<u-picker :show="pickerShow" :columns="columns" keyName="label" immediateChange
					:defaultIndex="defaultIndex" @confirm="pickerConfirm" @cancel="pickerCancel"></u-picker>
				<!-- 	<view class="qysf_box">
					<view class="qysf_item" :class="qiyeshenfen == 2 ? 'active' : ''"  @click="clickshenfen(2)">业主版</view>
					<view class="qysf_item" :class="qiyeshenfen == 4 ? 'active' : ''" @click="clickshenfen(4)">供应商版</view>
					<view class="qysf_item" :class="qiyeshenfen == 1 ? 'active' : ''" @click="clickshenfen(1)">代理商版</view>
				</view> -->
			</view>
			<view class="qybg_qysf qybg_qysf2">
				<view class="qysf_title">
					报告版本
					<view v-show="typeActive !== 2">
						<u-icon name="info-circle" size="14"></u-icon>
					</view>
					<text class="qybg-tips" v-show="qiyeshenfen == 2 && typeActive == 0">
						业主企业分析报告包含，近期企业信息变更与招标业绩数据
					</text>
					<text class="qybg-tips" v-show="qiyeshenfen == 2 && typeActive == 1">
						业主招标业绩报告仅包含招标业绩数据
					</text>
					<text class="qybg-tips" v-show="qiyeshenfen == 4 && typeActive == 0">
						供应商企业分析报告包含，近期企业信息变更与中标业绩数据
					</text>
					<text class="qybg-tips" v-show="qiyeshenfen == 4 && typeActive == 1">
						供应商中标业绩报告仅包含中标业绩数据
					</text>
					<text class="qybg-tips" v-show="qiyeshenfen == 1 && typeActive == 0">
						代理机构企业分析报告包含，近期企业信息变更与代理招标业绩数据
					</text>
					<text class="qybg-tips" v-show="qiyeshenfen ==1 && typeActive == 1">
						代理机构代理招标业绩报告仅包含代理招标业绩数据
					</text>
				</view>
				<view class="qysf_box">
					<view class="qysf_item" :class="typeActive == 0 ? 'active':''" @click="clickversion(0)">企业报告</view>
					<view class="qysf_item disable" v-if="qiyeshenfen == 2 && zbcount <= 0" @click="clickdisabled">
						招标业绩报告</view>
					<view class="qysf_item" :class="typeActive == 1 ? 'active':''"
						v-if="qiyeshenfen == 2 && zbcount > 0" @click="clickversion(1)">招标业绩报告</view>
					<view class="qysf_item disable" v-if="qiyeshenfen == 4 && gyscount <= 0" @click="clickdisabled">
						中标业绩报告</view>
					<view class="qysf_item" :class="typeActive == 1 ? 'active':''"
						v-if="qiyeshenfen == 4 && gyscount > 0" @click="clickversion(1)">中标业绩报告</view>
					<view class="qysf_item disable" v-if="qiyeshenfen == 1 && dlcount <= 0" @click="clickdisabled">
						代理业绩报告</view>
					<view class="qysf_item" :class="typeActive == 1 ? 'active':''"
						v-if="qiyeshenfen == 1 && dlcount > 0" @click="clickversion(1)">代理业绩报告</view>
					<view class="qysf_item fenxibaogao" :class="typeActive == 2 ? 'active':''"
						v-show="qiyeshenfen == 4 && !isqyztb" @click="clickversion(2)">企业招投标数据分析报告</view>
				</view>
			</view>
			<view class="qybg_qysf" v-show="qiyeshenfen == 4 && isshowEmail">
				<view class="qysf_title">接收邮箱</view>
				<view class="qybg_jsyx">
					<u--input placeholder="请输入报告接收邮箱" border="surround" v-model="email"></u--input>
				</view>
			</view>
			<!-- 支付方式 -->
			<view class="infor_quanyi" v-if="!baseConfig.isIOSshenhe && (!isbuy || qiyeshenfen == 4 && isshowEmail)">
				<view class="payment">
					<radio-group @change="radioChange" class="payment_radio">
						<label class="pay-list-cell pay-list-cell-pd" v-for="(payment, index) in payments"
							:key="payment.value">
							<view>
								<image :src="payment.tupic" class="pay-tupic"></image>
								{{payment.name}}
							</view>
							<view style="margin-left: 20rpx;">
								<radio :value="payment.value" :checked="paymentItem.id == payment.value"
									:type="payment.value" color="#74df63" />
							</view>
						</label>
					</radio-group>
				</view>
			</view>
			<view class="qyxq-foot">
				<view class="qyxq-foot-item" @click="zaixiankefu">
					<image src="https://img.bidcenter.com.cn/uni/qiqing/foot-kefu.png"></image>
					<text>客服</text>
				</view>
				<!-- <view class="qyxq-foot-item">
					<button open-type="share">
						<image src="https://img.bidcenter.com.cn/uni/detail/fenxiang.png"></image>
						<text>分享</text>
					</button>
				</view> -->
				<view class="qyxq-foot-item2" v-if="!isbuy" @click="gobuy">
					立即购买 ¥<text>{{sjprice}}</text>
				</view>
				<view class="qyxq-foot-item2" v-else-if="qiyeshenfen == 4 && isshowEmail" @click="gobuy">
					立即购买 ¥<text>{{sjprice}}</text>
				</view>
				<view class="qyxq-foot-item2" v-else-if="isbuy" @click="toDownload">
					立即下载
				</view>
			</view>
		</view>

		<!-- 企业报告购买成功弹窗 -->
		<u-modal :show="isshowreport" :content='reportText' confirmText='立即查看' :showCancelButton="true"
			cancelText='暂不查看' @confirm="lijichakan" @cancel="quxiaochakan"></u-modal>

		<!-- 企业招投标数据分析报告立即购买成功弹窗 -->
		<u-modal :show="isshowNotice" :content='noticeText' @confirm="confirm"></u-modal>

		<!-- 支付状态弹窗 -->
		<u-popup :show="showPayModal" mode="center" :closeOnClickOverlay="true" @close="close" @open="open"
			:closeable="true" border-radius="10">
			<view style="width:600rpx;">
				<h3 class="pay-popup-tit">支付遇到问题?</h3>
				<view style="padding:5% 10%;">支付完成前，请不要关闭该窗口，完成支付请根据您的情况点击下面的按钮</view>
				<view class="btnWrap2">
					<view class="btn btnOver" @click="payConfirm">已完成支付</view>
					<view class="btn btnRepeat" @click="gobuy()">重新支付</view>
				</view>
			</view>

		</u-popup>

		<!-- h5 支付页 -->
		<web-view :fullscreen="false" v-if="isUseH5Pay" :src="src" :webview-styles="webviewStyles"></web-view>

	</view>
</template>

<script>
	export default {

		data() {
			return {
				webviewStyles: {
					// progress:{
					// 	color: '#f00'
					// },
					height: 0,
					top: 50,
					bottom: 0
				},
				isUseH5Pay: false,
				src: '',
				loadingPageText: '正在加载...',
				title: '企业报告',
				email: '',
				qiyeshenfen: 2, // 1：招标代理 2：业主单位 5：中标单位
				typeActive: 0,
				count: 5,
				location: '11384',
				comcode: "",
				company: "",
				type: '249',
				sjprice: 0,
				yuanjia: 0,
				isPageLoading: true,
				vcode: "",
				zbcount: 0,
				gyscount: 0,
				dlcount: 0,
				isqyztb: false,
				isAllowDaochu: false,
				isbuy: false,
				dcComReportKey2: [],
				isshowEmail: false,
				ztbActive: 0,

				isshowNotice: false,
				noticeText: '稍后将有数据经理为您一对一服务，解析该公司的数据情况，请注意来电。',
				billStr: [{
					id: '',
					areacode: '',
					keyList: [{
						key: '',
						key2: ''
					}],
					count: 1
				}],
				CompanyUUID: '',
				isshowreport: false,
				reportText: '下载后可前往PC”用户中心-账号中心-我的报告“反复查看',
				priceLoading: true,
				isAllowAll: false, //企业报告是否完整下载
				buyLoading: true,
				columns: [
					[{
						label: '业主版',
						type: '2'
					}, {
						label: '供应商版',
						type: '4'
					}, {
						label: '代理版',
						type: '1'
					}]
				],
				pickerShow: false,
				defaultIndex: [0],
				callback: '',
				payments: [{
						value: 'alipay',
						tupic: "/static/img/huiyuan/zhifubao.png",
						name: '支付宝支付'
					},
					{
						value: 'wxpay',
						name: '微信支付',
						tupic: "/static/img/huiyuan/weixin.png",
						checked: 'true'
					}
				],
				// 支付方式
				paymentItem: {
					id: 'alipay'
				},
				lockPayBtn: false,
				IAPOrders: [],
				iapnotifycount: 0,
				orderid: '',
				// 支付相关
				showPayModal: false,
				// 计划创建的webview
				wv: '',
				//ios手机支付状态显示
				showPayModal: false,
			};
		},
		onLoad(option) {
			this.$onLaunched
			// const emailInfo = this.$root.userinfo.email
			// if(emailInfo !== null || emailInfo !==''){
			// 	this.email = emailInfo
			// }
			this.company = option.company
			this.comcode = option.comcode
			this.vcode = option.vcode
			this.callback = option.callback ? decodeURIComponent(option.callback) : '/pages/user/index'

			this.qiyeshenfen = option.danweiType == '5' ? '4' : option.danweiType
			// console.log(this.qiyeshenfen,option.danweiType)
			if (this.qiyeshenfen == '2') {
				this.defaultIndex = [0]
			} else if (this.qiyeshenfen == '4') {
				this.defaultIndex = [1]
			} else {
				this.defaultIndex = [2]
			}
			this.getcompanyinfo()
			//this.GetBuyState()

			// ios 审核期间走apple应用内 支付
			if (uni.getSystemInfoSync().platform == 'ios') {
				this.isios = true;
				if (this.baseConfig.isIOSshenhe) {
					// uni.switchTab({
					// 	url: '/pages/user/user'
					// })
					// return false;
					this.paymentItem.id = "appleiap";
				}
			}

			// #ifdef APP-PLUS
			// this.wv = plus.webview.create("", "bidcenter", {
			// 	// plusrequire: "none", //禁止远程网页使用plus的API，有些使用mui制作的网页可能会监听plus.key，造成关闭页面混乱，可以通过这种方式禁止
			// 	// 'uni-app': 'none', //不加载uni-app渲染层框架，避免样式冲突
			// 	// top: uni.getSystemInfoSync().statusBarHeight +
			// 	// 	44 //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的，可以继续降低TOP值
			// 	top: '50',
			// 	bottom: 0,
			// 	height: 0
			// })
			// #endif
		},
		async onShow(options) {
			this.isUseH5Pay = false;
			// const me = this;
			// // 原因是:页面onshow优先级高于应用onshow--微信支付会显示支付状态弹窗，支付宝没有
			// if (this.isios && !this.baseConfig.isIOSshenhe) {
			// 	setTimeout(function() {
			// 		// 显示支付状态Popup
			// 		if (getApp().globalData.from === 'bidcenter.com.cn://' || me.showPayModal) {
			// 			me.showPayModal = true;
			// 		}
			// 	}, 300)
			// }
		},
		computed: {
			// 支付方式是：鸿蒙且为微信支付
			isharmonyosWxpay() {
				return uni.getSystemInfoSync().platform === 'harmonyos' && this.paymentItem.id == "wxpay"
			}
		},
		methods: {

			//企业报告购买成功后点击立即查看
			lijichakan() {
				this.toDownload()
				this.GetBuyState()
			},
			quxiaochakan() {
				this.isshowreport = false
				this.GetBuyState()
			},

			//获取公司信息
			getcompanyinfo() {
				uni.$u.http
					.post('/analysis/Company/CompanyInfoHandler.ashx', {
						location: this.location,
						comcode: this.comcode,
						vcode: this.vcode,
						comType: this.qiyeshenfen, //1：代理；2：业主；4/5：供应商
					}).then(rs => {
						this.isPageLoading = false
						const data = rs.reportData
						data.map(item => {
							if (item.type == 1) {
								this.dlcount = item.count
							} else if (item.type == 2) {
								this.zbcount = item.count
							} else if (item.type == 4) {
								this.gyscount = item.count
							}
						})
						this.CompanyUUID = rs.CompanyUUID
						this.dcComReportKey2 = rs.dcComReportKey2
						this.isAllowDaochu = rs.isAllowDaochu
						this.getprice()
						// if(this.isAllowDaochu && this.dcComReportKey2.length > 0){
						// 	this.isbuy = true
						// }
					}).catch(err => {
						uni.$u.toast(err.msg);
					})
			},
			//无相关下载项
			clickdisabled() {
				uni.$u.toast('暂无相关数据，不可下载')
			},
			// clickztb(){
			// 	this.ztbActive = 1
			// 	this.typeActive = 0
			// 	this.isshowEmail = true
			// },

			clickshenfen(type) {
				this.qiyeshenfen = type
				this.typeActive = 0
				if (type == 1 && this.typeActive == 0 || type == 2 && this.typeActive == 0 || type == 4 && this
					.typeActive == 0) {
					this.type = '249'
				}
				if (type == 4 && this.typeActive == 2) {
					this.isshowEmail = true
				} else {
					this.isshowEmail = false
				}
				this.getprice()
			},
			clickversion(type) {
				this.typeActive = type
				// console.log(this.qiyeshenfen,this.typeActive)
				if (this.qiyeshenfen == 4 && this.typeActive == 1) {
					this.type = '257'
					this.isshowEmail = false
				} else {
					if ((this.qiyeshenfen == 2 && this.typeActive == 1) || (this.qiyeshenfen == 1 && this.typeActive ==
							1)) {
						this.type = '250'
					} else {
						if (this.qiyeshenfen == 4 && this.typeActive == 2) {
							this.isshowEmail = true
							this.type = '330'
						} else {
							this.type = '249'
							this.isshowEmail = false
						}
					}

				}
				// console.log('type',this.type,'企业身份',this.qiyeshenfen)
				this.getprice()
			},
			//获取价格
			//企业报告 249 招标业绩报告、代理业绩报告 250  中标业绩报告 257
			getprice() {
				uni.$u.http
					.post('pay/GetPriceHandler.ashx', {
						location: this.location,
						types: this.type
					}).then(rs => {
						this.sjprice = rs[0].sjprice
						this.yuanjia = rs[0].yuanjia
						this.$set(this.billStr[0], `id`, rs[0].jgid[0])
						this.$set(this.billStr[0].keyList[0], `key`, this.CompanyUUID)
						this.GetBuyState()
						this.priceLoading = false
						if (this.isios && this.baseConfig.isIOSshenhe) {
							this.plusReady()
						}
					}).catch(err => {
						uni.$u.toast(err.msg);
					})
			},
			//剩余次数
			GetBuyState() {
				let zbIsbuy = false
				let gysIsbuy = false
				let dlIsbuy = false
				uni.$u.http
					.post('/analysis/Company/CompanyReport/GetBuyStateHandler.ashx', {
						location: this.location,
						comcode: this.comcode,
						keyword: this.company
					}).then(rs => {
						this.count = rs.syCount
						const data = rs.buyInfo
						data.map(item => {
							if (this.qiyeshenfen == 2 && item.flid == 9414) {
								if (item.isbuy) {
									this.isbuy = true
								} else {
									this.isbuy = false
								}
								if (this.typeActive == 0) {
									this.$set(this.billStr[0].keyList[0], `key2`, '')
								} else {
									this.$set(this.billStr[0].keyList[0], `key2`, '9414')
								}
							} else if (this.qiyeshenfen == 4 && item.flid == 9415) {
								if (item.isbuy) {
									this.isbuy = true
								} else {
									this.isbuy = false
								}
								if (this.typeActive == 0) {
									this.$set(this.billStr[0].keyList[0], `key2`, '')
								} else {
									this.$set(this.billStr[0].keyList[0], `key2`, '9415')
								}

							} else if (this.qiyeshenfen == 1 && item.flid == 9416) {
								if (item.isbuy) {
									this.isbuy = true
								} else {
									this.isbuy = false
								}
								if (this.typeActive == 0) {
									this.$set(this.billStr[0].keyList[0], `key2`, '')
								} else {
									this.$set(this.billStr[0].keyList[0], `key2`, '9416')
								}
							}
						})
						// if(this.count > 0 && this.qiyeshenfen == 4){
						// 	this.isqyztb = !this.isqyztb
						// }
						this.isAllowAll = rs.isAllowAll //企业报告权限
						if (this.typeActive == 0) {
							if (!this.isAllowAll) {
								this.isbuy = false
							} else {
								this.isbuy = true
							}
						}
						// console.log('企业报告',this.isbuy)
						this.buyLoading = false
						this.isPageLoading = false
					}).catch(err => {
						uni.$u.toast(err.msg);
					})
			},
			//立即购买--购买完成版企业报告时，key2不应该有值
			gobuy() {
				// console.log(this.type,this.billStr)
				if (this.qiyeshenfen == 4 && this.isshowEmail) {
					this.goZtbPay()
				} else {
					if (this.lockPayBtn) return;
					this.lockPayBtn = true;
					this.requestPayment()
					// this.goyejiPay()
				}
			},
			// 点击 立即开通按钮
			async requestPayment() {
				const me = this;
				console.log('支付', this.isios, this.baseConfig.isIOSshenhe)
				uni.showLoading({
					title: '订单处理中...'
				});
				if (this.isios && this.baseConfig.isIOSshenhe) {
					this.paymentItem.id = "appleiap";
				}

				let orderInfo = await this.getOrderInfo();
				console.log('orderInfo', orderInfo)
				this.orderid = orderInfo.orderid || ''

				if ((uni.getSystemInfoSync().platform === 'android' && orderInfo.statusCode !== 200) || (this.isios &&
						!this.baseConfig.isIOSshenhe && !
						orderInfo.orderid) || (this.isharmonyosWxpay && !orderInfo.orderid)) {
					uni.showModal({
						content: "获得订单信息失败",
						showCancel: false
					})
					this.hideLoading()
					return;
				}

				// && this.baseConfig.isIOSshenhe
				if (this.isios || this.isharmonyosWxpay) {
					// 更新支付弹窗显示条件,重置为应用初始值
					// getApp().globalData.from = ''

					if (this.baseConfig.isIOSshenhe) {
						this.pay(orderInfo.data)
					} else {
						setTimeout(() => {
							this.showPayModal = true;
						}, 5000);
						// 注：想唤起微信支付界面时，必须用网络地址；而支付宝及电脑端（只能唤醒微信，打开微信，不能支付）用上面的本地地址也可以
						const h5pay = 'https://m.bidcenter.com.cn/pay/pay-jsapi.html?orderid=' + orderInfo
							.orderid +
							'&token=' + this.initNewData().token + '&from=open'
						// uni.navigateTo({
						// 	url: '/pages/webView/webView?url=' + h5pay
						// });					
						// console.log(h5pay)
						// this.webviewfn(h5pay)
						this.src = h5pay;
						this.isUseH5Pay = true;
						setTimeout(() => {
							uni.hideLoading()
							// 解锁
							this.lockPayBtn = false;
						}, 1000)
					}
					return
				} else {
					uni.requestPayment({
						provider: this.paymentItem.id,
						orderInfo: orderInfo.data,
						success: (e) => {
							// console.log("success", e);
							uni.$u.toast('支付成功');
							setTimeout(() => {
								this.isshowreport = true
							}, 1000)
						},
						fail: (e) => {
							// console.log(e)
							uni.$u.toast('支付失败');
							this.payFail(rs.order_id)
						},
						complete: () => {
							// 解锁
							this.lockPayBtn = false;
							uni.hideLoading()
						}
					})

					// 鸿蒙打开时：会先询问是否允许支付宝支付，如果不允许，需要执行以下代码才可结束loading
					setTimeout(() => {
						uni.hideLoading()
						// 解锁
						this.lockPayBtn = false;
					}, 5000)

				}

			},
			getOrderInfo() {
				let data = {};
				// data.location =this.location;
				// yyb huawei xiaomi oppo
				// 	if (uni.getSystemInfoSync().platform == 'ios') {
				// 		data.qudao = 'ios';
				// 	} else {
				// 		// getApp()在ios中打断点输出的是路由,初步怀疑该方法有bug，故加上面的条件
				// 		data.qudao = getApp().globalData.channel;
				// 		// data.qudao = ''
				// 	}

				// let appid = "";
				// // #ifdef APP-PLUS
				// appid = plus.runtime.appid;
				// // #endif

				// 正常来说，只有android中的接口会用到；苹果应用于支付不太清楚
				//分步买 callpay传1，安卓买传0 20250409
				if (this.isios && this.baseConfig.isIOSshenhe) {
					// 	// ios 审核内，统一下单接口
					data.payid = this.paymentItem.id; //wxpay：微信支付，alipay：支付宝支付，weworkpay：企业微信(小程序)
					data.billStr = JSON.stringify(this.billStr);
					data.callPay = 1; //默认0：是；1：否

				} else if (uni.getSystemInfoSync().platform === 'android' || (uni.getSystemInfoSync().platform ===
						'harmonyos' && this.paymentItem.id == "alipay")) {
					// android 统一下单接口
					data.payid = this.paymentItem.id; //wxpay：微信支付，alipay：支付宝支付，weworkpay：企业微信(小程序)
					data.billStr = JSON.stringify(this.billStr);
					data.callPay = 0; //默认0：是；1：否

				} else {
					data.payid = this.paymentItem.id; //wxpay：微信支付，alipay：支付宝支付，weworkpay：企业微信(小程序)
					data.billStr = JSON.stringify(this.billStr);
					data.callPay = 1; //默认0：是；1：否
				}
				data.qudao = getApp().globalData.channel;


				// console.log('ios',this.baseConfig.isIOSshenhe,data,this.paymentItem.id)
				return new Promise((res) => {
					uni.$u.http
						.post('pay/CreateOrderHandlerV3.ashx', data).then(rs => {
							console.log(rs)
							res(rs)
						}).catch(err => {
							console.log(data, err)
							this.lockPayBtn = false
							uni.$u.toast(err.msg);
						})
				})

			},
			// goyejiPay() {

			// 	uni.showLoading({
			// 		title: '正在支付...'
			// 	})
			// 	uni.$u.http
			// 		.post('pay/CreateOrderHandlerV3.ashx', {
			// 			location: this.location,
			// 			payid: 'weworkpay', //wxpay：微信支付，alipay：支付宝支付，weworkpay：企业微信(小程序)
			// 			billStr: JSON.stringify(this.billStr)

			// 		}).then(rs => {
			// 			const data = rs.data
			// 			const me = this
			// 			uni.requestPayment({
			// 				provider: data.provider,
			// 				timeStamp: data.timeStamp,
			// 				nonceStr: data.nonceStr,
			// 				package: data.package,
			// 				signType: data.signType,
			// 				paySign: data.paySign,
			// 				success: function(res) {
			// 					uni.$u.toast('支付成功');
			// 					setTimeout(() => {
			// 						me.isshowreport = true
			// 					}, 1000)

			// 				},
			// 				fail: function(err) {
			// 					uni.$u.toast('支付失败');
			// 					me.payFail(rs.order_id)
			// 				}
			// 			});
			// 		}).catch(err => {
			// 			uni.$u.toast(err.msg);
			// 		})
			// },
			payFail(orderId) {
				uni.redirectTo({
					url: '/pages/user/goumaijilu/goumaijilu'
				})
			},
			goZtbPay() {
				if (!uni.$u.test.email(this.email)) {
					uni.$u.toast('邮箱格式不正确请检查');
					return;
				}
				uni.$u.http
					.post('analysis/Company/CompanyReport/PaymentReportHandler.ashx', {
						location: this.location,
						company: this.company,
						email: this.email
					}).then(rs => {
						this.isshowNotice = true
					}).catch(err => {
						uni.$u.toast(err.msg);
					})
			},
			confirm() {
				this.isshowNotice = false
				uni.redirectTo({
					url: this.callback
				})
			},

			//下载
			toDownload() {
				uni.showLoading({
					title: '正在下载...'
				})
				// console.log('下载',this.company,this.qiyeshenfen)
				uni.$u.http
					.post('/analysis/Company/CompanyReport/ExportPDFHandler.ashx', {
						location: this.location,
						keyword: this.company,
						comtype: this.qiyeshenfen //bug文档报错部分
					}).then(rs => {
						let link = rs.url
						this.xiazai(link)
					}).catch(err => {
						console.log(err)
						uni.$u.toast(err.msg);
					})
			},
			xiazai(url) {
				uni.downloadFile({
					url: url.replace('http', 'https'),
					success: (res) => {
						// console.log(res)
						if (res.statusCode === 200) {
							uni.$u.toast('下载成功');
							this.isshowEmail = false
						}
						let that = this;
						uni.saveFile({
							tempFilePath: res.tempFilePath,
							success: function(red) {
								uni.openDocument({
									filePath: red.savedFilePath,
									success: (res) => console.log('成功打开文档'),
									fail: (res) => {
										console.log('打开文档失败')
									}
								})
							}
						})
					}
				})
			},

			// 在线客服
			zaixiankefu() {
				uni.navigateTo({
					url: '/pages/user/service/service',
				})
			},
			shenfenChange() {
				this.pickerShow = true
			},

			//picker
			pickerConfirm(e) {
				let type = e.value[0].type
				// console.log(111,type)
				this.qiyeshenfen = type
				this.typeActive = 0
				if (type == 1 && this.typeActive == 0 || type == 2 && this.typeActive == 0 || type == 4 && this
					.typeActive == 0) {
					this.type = '249'
				}
				if (type == 4 && this.typeActive == 2) {
					this.isshowEmail = true
				} else {
					this.isshowEmail = false
				}
				this.pickerShow = false
				// console.log('切换',this.qiyeshenfen)
				this.getprice()
			},
			pickerCancel() {
				this.pickerShow = false
			},
			//支付相关
			radioChange: function(evt) {
				//console.log(evt)
				// this.paymentItem.id = evt.target.value;
				this.paymentItem.id = evt.detail.value;
				this.lockPayBtn = false;
				uni.hideLoading()
			},

			plusReady() { //uni-app中将此function里的代码放入vue页面的onLoad生命周期中
				// 获取支付通道 
				let that = this;

				return new Promise((res) => {
					// console.log(1, res)

					// #ifdef APP-PLUS
					plus.payment.getChannels(function(channels) {
						for (var i = 0; i < channels.length; i++) {
							// console.log(channels)
							if (channels[i].id == 'appleiap') {
								iapChannel = channels[i];
								//console.log("进入方法appleiap " + that.IAPOrders)
								iapChannel.requestOrder(that.IAPOrders, function(event) {
									uni.hideLoading();
									console.log("获取支付通道成功")
									//console.log(JSON.stringify(event))
								}, function(errormsg) {
									uni.hideLoading();
								});
							}
						}
					}, function(e) {
						uni.showModal({
							content: "获取支付通道失败,请重新进入", //+ e.message,
							showCancel: false,
							success: function() {
								uni.navigateBack({
									delta: 1
								});
							}
						});
						//console.log("获取支付通道失败：" + e.message);
					});
					// #endif

				})
			},
			async pay(e) {
				// console.log(e)
				let that = this;
				console.log('e', iapChannel)
				uni.showLoading({
					title: '支付中，请稍后'
				});
				// setTimeout(()=>{
				// 	uni.hideLoading();
				// 	// 解锁
				// 	this.lockPayBtn = false;
				// }, 1000)
				plus.payment.request(iapChannel, {
					"productid": e.productid,
					"username": e.username,
					"quantity": e.quantity
				}, function(result) {

					// 解锁
					that.lockPayBtn = false;
					uni.hideLoading();

					if (result != undefined && result != null && result.transactionIdentifier !=
						undefined &&
						result.transactionIdentifier !=
						null && result.transactionReceipt != undefined && result
						.transactionReceipt != null) {
						//添加订单缓存，防止掉单
						uni.setStorageSync("iaporderinfo", result);
						uni.setStorageSync("iaporderinfolocal", e);

						//验证订单
						that.iapnotify(result, e, false);
					} else {
						uni.showToast({
							title: '未获取到订单信息！',
							icon: "none"
						});
					}
				}, function(e) {
					// console.log(e)
					// 解锁
					that.lockPayBtn = false;
					uni.hideLoading();

					uni.showModal({
						content: "下单失败，请重试", //+ JSON.stringify(e),
						showCancel: false
					});
				});
			},
			iapnotify(result, order, ischeck) {
				let that = this;
				let data = this.initNewData();
				data.location = 5181;
				data.orderid = order.orderid;
				//console.log("支付回调方法");
				data.transactionid = result.transactionIdentifier;
				data.receipt = result.transactionReceipt;
				data.payment = JSON.stringify(result.payment);
				uni.request({
					url: this.baseConfig.serverURL +
						'pay/iap/IosiapNotifyHandler.ashx', //检查更新的服务器地址
					data: data,
					method: "POST",
					header: {
						"content-type": "application/x-www-form-urlencoded" //"application/json"
					},
					success: (res) => {
						if (res.statusCode == 200) {
							if (!res.data.ret) {
								uni.showToast({
									title: res.data.msg,
									icon: "none"
								});
							} else {
								//移除订单缓存
								try {
									uni.removeStorage({
										key: 'iaporderinfo',
										success: function(res) {
											//console.log('iaporderinfo remove success');
										}
									});
									uni.removeStorage({
										key: 'iaporderinfolocal',
										success: function(res) {
											//console.log('iaporderinfolocal remove success');
										}
									});
								} catch (e) {}

								if (!ischeck) {
									uni.showToast({
										title: res.data.msg,
										success: function() {
											setTimeout(function() {
												uni.navigateBack({
													delta: 1
												});
											}, 2000)
										}
									})
								}
							}
						} else {
							uni.showToast({
								title: '购买企业报告失败！',
								icon: "none"
							});
						}
					},
					fail: (e) => {
						that.iapnotifycount++;
						if (that.iapnotifycount < 5) {
							that.iapnotify(result, order, false)
						} else {
							uni.showToast({
								title: '购买企业报告失败，可能网络超时！',
								icon: "none"
							});
						}

					}
				})

			},
			open() {
				this.showPayModal = true;
			},
			close() {
				this.showPayModal = false;
				// getApp().globalData.from = 'isclose'
				this.showPayModal = false
			},
			// 已完成支付
			payConfirm() {
				// 确认支付结果
				this.getPayState();
			},
			// 获取支付状态
			getPayState() {
				let data = this.initNewData();
				data.location = this.location;
				data.type = "1" // 支付类别	string	Y	0（默认）：二码合一扫码支付 1：直接支付
				data.orderid = this.orderid //
				uni.request({
					url: this.baseConfig.serverURL + '/pay/GetPaySuccessToCecheHandler.ashx', //检查更新的服务器地址
					data: data,
					method: "POST",
					header: {
						"content-type": "application/x-www-form-urlencoded" //"application/json"
					},
					success: (res) => {
						// console.log(22,res)
						if (res.data.ret) {
							this.close()
							setTimeout(() => {
								this.showPayModal = false
								uni.$u.toast('支付成功');
								this.isshowreport = true
							}, 1000)
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: "none"
							});
						}
					},
					fail: (e) => {
						uni.showToast({
							title: '服务器异常',
							icon: "none"
						});
					}
				})
			},
		},


	}
</script>

<style lang="scss">
	@import "@/static/css/index.scss";

	.qybg_top {
		background: url('https://img.bidcenter.com.cn/uni/qiqing/caizhaoyingyong/qybg_bg.png') no-repeat;
		width: 100%;
		height: 331rpx;
		background-size: 100% 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;

		.title {
			font-weight: 800;
			font-size: 36rpx;
			padding-left: 52rpx;
		}

		.company {
			font-size: 28rpx;
			color: #606266;
			margin-top: 20rpx;
			padding-left: 52rpx;
		}
	}

	.qybg_price {
		padding: 30rpx 28rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.xianjia {
			font-weight: bold;
			font-size: 36rpx;
			color: #FF1717;
		}

		.yuanjia {
			font-size: 24rpx;
			color: #6C717E;
			margin-left: 10rpx;
		}

		.cishu {
			font-size: 24rpx;

			text {
				color: #FF1717;
				font-weight: bold;
			}
		}
	}

	.qybg_qysf {
		margin-bottom: 30rpx;
		margin-left: 28rpx;

		.qysf_title {
			font-weight: bold;
			font-size: 28rpx;
			margin-bottom: 20rpx;
		}

		.qysf_box {
			display: flex;
		}

		.qysf_item {
			width: 218rpx;
			height: 68rpx;
			border-radius: 10rpx;
			border: 1rpx solid #ADB4C2;
			font-size: 28rpx;
			color: #ADB4C2;
			line-height: 68rpx;
			text-align: center;
			margin-right: 20rpx;
			box-sizing: border-box;

			&.active {
				border: 1rpx solid #2F6DFE;
				color: #2F6DFE;
			}
		}

	}

	.qybg_qysf2 {
		.qysf_title {
			display: flex;
			align-items: center;
		}

		.qybg-tips {
			font-size: 19rpx;
			font-weight: normal;
		}

		.qysf_box {
			flex-wrap: wrap;

			.fenxibaogao {
				width: auto;
				padding: 0 20rpx;
				margin-top: 20rpx;
			}
		}
	}

	.qybg_jsyx {
		margin-right: 28rpx;

		.u-input {
			height: 96rpx;
			box-sizing: border-box;
		}
	}

	.qyxq-foot {
		position: fixed;
		bottom: 0;
		padding: 25rpx 28rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-top: 1px solid #EEEEEE;
		background-color: #fff;
		z-index: 9;
		box-sizing: border-box;

		.qyxq-foot-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 0 20rpx;

			image {
				width: 40rpx;
				height: 40rpx;
				display: block;
			}

			text {
				font-size: 28rpx;
				color: #6C717E;
				margin-top: 8rpx;
			}

			button {
				border: 0;
				background: transparent !important;
				padding: 0;
				line-height: initial;
				display: flex;
				flex-direction: column;
				align-items: center;

				&::after {
					border: initial;
				}
			}
		}

		.qyxq-foot-item2 {
			height: 80rpx;
			border-radius: 10rpx;
			line-height: 80rpx;
			font-weight: bold;
			font-size: 28rpx;
			background: #FE6B2F;
			margin-left: 20rpx;
			color: #FFFFFF;
			width: 554rpx;
			text-align: center;
		}
	}

	.disable {
		background-color: #F2F2F2 !important;
		border-color: #F2F2F2 !important;
		cursor: default !important;
		color: #AAAAAA !important;
		font-weight: normal !important;
	}

	.infor_quanyi {
		margin: 0 30rpx 140rpx;
		// margin-top: 15rpx;
		background-color: #FFFFFF;
	}

	.payment {
		display: flex;
		flex-direction: column;
		padding: 39rpx 0;

		.payment_radio {
			flex-direction: column;
			display: flex;
			// margin: 0 15px;

			.pay-list-cell {
				flex-direction: row;
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				font-size: 32rpx;
				// margin-bottom: 30rpx;
				padding-bottom: 28rpx;

				&:last-child {
					padding: 0;
				}
			}
		}

		.pay-tupic {
			width: 55rpx;
			height: 54rpx;
			vertical-align: middle;
			margin-right: 20rpx;
		}
	}

	.discountBox {
		// margin: 0 30rpx 0;
		margin-bottom: 42rpx;

		.discount {
			display: flex;
			align-items: center;

			h2 {
				font-size: 30rpx;
				margin-left: 16rpx;
				font-weight: 500;
			}
		}

		.discountInfo {
			display: flex;
			align-items: center;
			justify-content: space-between;
			// margin-top: 43rpx;
			padding: 40rpx 21rpx;
			background: #FFFFFF;
			border-radius: 8rpx;
			border: 1px solid #C5C5C5;
			font-size: 30rpx;

			image {
				width: 48rpx;
				height: 33rpx;
				margin-right: 20rpx;
			}

			.jianmian {
				color: #F24949;
				font-weight: bold;
				font-size: 28rpx;
				// margin-left: 175rpx;
			}

			.jianmian2 {
				color: #BFBFBF;
				font-weight: bold;
				font-size: 36rpx;
			}
		}
	}

	.pay-popup-tit {
		padding: 21px 0 0px;
		text-align: center;
	}

	.invisible {
		visibility: hidden;
	}

	.btnWrap2 {
		display: flex;
		justify-content: center;
		padding-bottom: 50rpx;

		.btn {
			width: 234rpx;
			white-space: nowrap;
			background-color: #f4f5f7;
			text-align: center;
			padding: 2% 0;
			color: #868789;
			border-radius: 7rpx;

			&:first-child {
				background-color: #304aff;
				margin-right: 8%;
				color: #fff;

			}
		}
	}
</style>